//货代报价信息表的crud

import axios from "axios";
import {ElMessage} from "element-plus";

//添加货代报价信息数据
export async function saveFreightForwarder(data){
    try {
        const response = await axios.post('http://localhost:8888/freight_forwarder/save',data)
        if (response.data.code === '00000'){
            ElMessage.success('添加成功!')
        }else {
            ElMessage.error(response.data.message)
        }
    }catch (e) {
        ElMessage.error(e.message)
    }
}

//修改货代报价信息数据
export async function modifyFreightForwarder(data){
    try {
        const response = await axios.post('http://localhost:8888/freight_forwarder/modify',data)
        if (response.data.code === '00000'){
            ElMessage.success('修改成功!')
        }else {
            ElMessage.error(response.data.message)
        }
    }catch (e) {
        ElMessage.error(e.message)
    }
}

//修改货代报价信息数据
export async function removeFreightForwarder(data){
    try {
        const response = await axios.post('http://localhost:8888/freight_forwarder/remove_by_id',data)
        if (response.data.code === '00000'){
            ElMessage.success(`删除${data.forwarderId}成功!`)
        }else {
            ElMessage.error(response.data.message)
        }
    }catch (e) {
        ElMessage.error(e.message)
    }
}

//根据fba获取货代信息
export async function getFreightForwarderByFba(data){
    try {
        const response = await axios.post('http://localhost:8888/freight_forwarder/get_by_fba',data)
        if (response.data.code === '00000'){
            return response.data.data || []
        }else {
            ElMessage.error(response.data.message)
        }
    }catch (error) {
        console.log(error.message)
    }
}